﻿using UnityEngine;
using System.Collections;

public class turn : MonoBehaviour
{
    RaycastHit Hit;

    float TurnSpeed;

    Vector3 Click;

    Quaternion dir;

    // Use this for initialization
    void Start()
    {
        TurnSpeed = 5f;
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButton(0))
        {	//왼쪽 버튼 누르
            Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out Hit);

            Click = Hit.point; // 히트된 부분을 가져와서 클릭에 저

            dir = Quaternion.LookRotation((Click - transform.position).normalized);
            dir.x = 0;
            dir.z = 0;
            transform.rotation = Quaternion.Slerp(transform.rotation, dir, TurnSpeed * Time.deltaTime);
        }
    }
}
